package gp;

import java.util.HashMap;

public class Alphabet {
	HashMap<String, Symbol> terminalSymbols;
	HashMap<String, Symbol> nonTerminalSymbols;
	
	public Alphabet(){
		this.terminalSymbols = new HashMap<String, Symbol>();
		this.nonTerminalSymbols = new HashMap<String, Symbol>();
		//the first symbol is the empty one
		this.terminalSymbols.put("EMPTY", new Symbol(0));
		this.nonTerminalSymbols.put("EMPTY", new Symbol(2));
	}
	
	public void insert_symbol(String symbol, int degree){
		//O Símbolo vazio (EMPTY) sempre será o símbolo de maior valor
		if (degree == 0) {
			int value = this.terminalSymbols.size() - 1;
			this.terminalSymbols.put(symbol, new Symbol(symbol, value, degree));
			Symbol.setValor_EMPTY_terminal(value + 1);
			this.terminalSymbols.put("EMPTY", new Symbol(0));
		}
		else if (degree == 2) {
			int value = this.nonTerminalSymbols.size() - 1;
			this.nonTerminalSymbols.put(symbol, new Symbol(symbol, value, degree));
			Symbol.setValor_EMPTY_nonTerminal(value + 1);
			this.nonTerminalSymbols.put("EMPTY", new Symbol(2));
		}
	}
	
	public Symbol get_symbol(String symbol){
		Symbol aux = this.terminalSymbols.get(symbol);
		if (aux == null) {
			aux = this.nonTerminalSymbols.get(symbol);
		}
		return aux;
	}
	
	public int terminals_size(){
		return this.terminalSymbols.size();
	}
	
	public int non_terminals_size(){
		return this.nonTerminalSymbols.size();
	}
}
